local skel = fk.CreateSkill {
  name = "rmt__bingfa",
  tags = {Skill.Compulsory, Skill.Lord},
}

Fk:loadTranslationTable{
  ["rmt__bingfa"] = "兵伐",
  [":rmt__bingfa"] = "主公技，锁定技，非主公外的其他角色的身份改为内奸，且游戏结束时所有角色均胜利。",

  ["$rmt__bingfa1"] = "东海王骄肆日久，爱卿奉朕明诏，速讨灭之！",
  ["$rmt__bingfa2"] = "石贼乘隙纵难，臣工逡巡，竟使群狼窥伺于朕！",
}

skel:addEffect(fk.EventAcquireSkill, {
  anim_type = "drawcard",
  priority = 0.001,
  can_trigger = function (self, event, target, player, data)
    return data.skill.name == skel.name and target == player and player:hasSkill(skel.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setBanner("rmt__bingfa", true)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if p.role ~= "lord" then
        room:setPlayerProperty(p, "role_shown", true)
        room:setPlayerProperty(p, "role", "renegade")
      end
    end
  end,
})

--- 游戏胜利前，将所有角色身份改为获胜阵营
skel:addEffect(fk.GameFinished, {
  can_refresh = function(self, event, target, player, data)
    return player.room:getBanner("rmt__bingfa")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setBanner("rmt__bingfa", nil)
    local winner = data
    if type(winner) ~= "string" or winner == "" then return end
    if string.find(winner, "+") then
      -- 主忠胜利，除了主公全变成忠臣
      local roles = string.split(winner, "+")
      winner = roles[1]
      local subrole = roles[#roles]
      for _, p in ipairs(room.players) do
        if p.role ~= winner then
          room:setPlayerProperty(p, "role", subrole)
        end
      end
    else
      for _, p in ipairs(room.players) do
        room:setPlayerProperty(p, "role", winner)
      end
    end
  end,
})


return skel
